package jee.boot.module.iexp.config;

import jee.boot.module.iexp.dao.IexpTaskDao;
import jee.boot.module.iexp.task.TaskListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 初始化导入导出环境
 */
@Component
public class InitIexp implements ApplicationRunner {

    /**
     * 日志对象
     */
    protected Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private IexpTaskDao iexpTaskDao;
    @Value("${spring.schema}")
    private String schema;
    @Autowired
    private TaskListener taskListener;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        logger.info("Iexp任务初始化");
        //初始化后台任务数据表
        /** 取消表自检功能,因为在hana数据库里当前sql会执行失败
        int exist = iexpTaskDao.existTable(schema);
        if (exist <= 0) {
            logger.info("初始建表:" + schema + ".st_iexp_task");
            logger.info("初始建表:" + schema + ".st_iexp_task_item");
            iexpTaskDao.createTable();
        }*/
        // 开始监听后台任务
        taskListener.listenTask();

    }
}
